package com.qs.rocketmq.order.controller;

import com.qs.rocketmq.common.base.BaseController;
import com.qs.rocketmq.common.util.JsonResult;
import com.qs.rocketmq.common.util.ResultObject;
import com.qs.rocketmq.order.dto.OrderDTO;
import com.qs.rocketmq.order.service.OrderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
public class OrderController extends BaseController {

    @Autowired
    private OrderService orderService;

    @GetMapping(value = "/order")
    public String order() {
        return "order";
    }

    @GetMapping(value = "/createOrder")
    public JsonResult crateOrder(OrderDTO orderDTO) {
        ResultObject<Object> result = orderService.createOrder(orderDTO);
        if (result.isSuccess()) {
            return successed(result);
        }

        return failed(result.getErrorCode());
    }
}
